﻿using PHMEE.ToolKits;
using Volo.Abp.Application.Services;

namespace PHMEE.Admin
{
    /// <summary>
    /// 操作超级表，子表，列,与测点关系的服务
    /// </summary>
    public interface ITdDeviceAppService : IApplicationService
    {
        /// <summary>
        /// 创建数据库
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<Guid> CreateDataBaseAsync(CreateDatabaseDto input);
        /// <summary>
        /// 获取所有数据库
        /// </summary>
        /// <returns></returns>
        Task<List<DatabaseDto>> GetAllDatabasesAsync();
        /// <summary>
        /// 根据数据库名称查询数据库是否已经存在
        /// </summary>
        /// <param name="dbName"></param>
        /// <returns></returns>
        Task<bool> GetDbNameAsync(string dbName);
        /// <summary>
        /// 删除数据库(会删除对应所有超级表）
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task DeleteDataBaseAsync(Guid id);
        /// <summary>
        /// 创建超级表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<Guid> CreateSuperTableAsync(CreateSuperTableDto input);
        /// <summary>
        /// 根据数据库ID获取超级表 
        /// </summary>
        /// <param name="databaseId"></param>
        /// <returns></returns>
        Task<List<SuperTableDto>> GetSuperTablesByDatabaseIdAsync(Guid databaseId);
        /// <summary>
        /// 删除超级表（会删除对应所有列和子表）
        /// </summary>
        /// <param name="superTableId"></param>
        /// <returns></returns>
        Task DeleteSuperTableAsync(Guid superTableId);
        /// <summary>
        /// 批量创建超级表的属性和更新属性
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        Task CreateUpdateAttributesForSuperTableAsync(CreateAndUpdateAttributesDto input);
        /// <summary>
        /// 根据超级表ID获取子表
        /// </summary>
        /// <param name="superTableId"></param>
        /// <returns></returns>
        Task<List<SubTableDto>> GetSubTablesBySuperTableIdAsync(Guid superTableId);
        /// <summary>
        /// 根据id获取超级表
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        Task<List<SubTableDto>> GetSubTablesAsync(List<Guid> ids);
        /// <summary>
        /// 删除单个属性
        /// </summary>
        /// <param name="attributeId"></param>
        /// <returns></returns>
        Task DeleteAttributeAsync(Guid attributeId);
        /// <summary>
        /// 创建子表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        Task<Guid> CreateSubTableAsync(CreateSubTableDto input);
        /// <summary>
        /// 删除单个子表
        /// </summary>
        /// <param name="subTableId"></param>
        /// <returns></returns>
        Task DeleteSubTableAsync(Guid subTableId);
        /// <summary>
        /// 根据超级表或子表ID获取属性
        /// </summary>
        /// <param name="tableId"></param>
        /// <param name="isSuperTable"></param>
        /// <returns></returns>
        Task<List<AttributeDto>> GetAttributesByTableIdAsync(Guid tableId, bool isSuperTable);

        /// <summary>
        /// 创建测点与子表实例关系
        /// </summary>
        /// <param name="relations"></param>
        /// <returns></returns>
        Task CreateOrUpdatePointRelationAsync(List<PointRelationDto> relations);

        /// <summary>
        ///  根据子表实例 ID 获取所有测点关系
        /// </summary>
        /// <param name="subTableId"></param>
        /// <returns></returns>
        Task<List<PointRelationDto>> GetRelationsByInstanceIdAsync(Guid subTableId);
        /// <summary>
        /// 获取测点与子表实例的关联关系集合。
        /// </summary>
        /// <param name="pointIds">测点集合</param>
        /// <returns></returns>
        Task<List<PointRelationDto>> GetRelationsAsync(List<Guid> pointIds);
        /// <summary>
        /// 删除测点与子表实例的关系--测点删除时执行
        /// </summary>
        /// <param name="pointIds"></param>
        /// <returns></returns>
        Task DeleteRelationsAsync(List<Guid> pointIds);
        /// <summary>
        /// 获取超级表和子表的结构--全部的数据
        /// </summary>
        /// <returns></returns>
        Task<List<SuperTableDto>> GetAllSuperTablesWithSubTablesAsync();

        /// <summary>
        /// 根据数据库名称生成超级表和子表的SQL脚本
        /// </summary>
        /// <param name="dbName">数据库名称</param>
        /// <returns></returns>
        Task GenerateSqlScriptsAsync(string dbName);

        /// <summary>
        /// 获取TdEngine属性列类型
        /// </summary>
        /// <returns></returns>
        List<OperationOptionInt> GetTdEngineAttributeDataTypes();

        /// <summary>
        /// 生成种子数据
        /// </summary>
        /// <param name="dbPrefix">数据库前缀</param>
        /// <param name="vesselId">船舶ID</param>
        /// <param name="dbDescription">数据库描述</param>
        /// <returns></returns>
        Task<bool> TdDataSeedAsync(DbPrefixEnum dbPrefix, Guid vesselId, string dbDescription);
    }
}
